<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Test Canvas</title>
    <style>
        .actions {
            text-align: center;
        }
        .actions button {
            margin: 5px;
        }
        .container {
            width: 1100px;
            min-height: 600px;
            margin: 0 auto;
            background: aliceblue;
        }
        .container canvas, .container .tracer {
            float: left;
        }
        .container .tracer {
            height: 550px;
            width: 540px;
            background: beige;
        }
    </style>
</head>
<body>
    <div class="actions">
        <button id="ch-opacity">opacity 0.5</button>
    </div>
    <div class="container">
        <canvas id="canvas" width="550" height="550"></canvas>
        <div class="tracer">
            这里是 div 容器
        </div>
    </div>
    <script>
        var $tracer = document.querySelector('.tracer')
        var $canvas = document.querySelector('#canvas')

        document.querySelector('#ch-opacity').addEventListener('click', function () {
            $tracer.style.opacity = 0.5
        })
        var ctx = $canvas.getContext('2d');
        ctx.clearRect(0, 0, 550, 550);
        ctx.fillText('这里是 canvas', 200, 200);

        // $(() => {
        //     var $tracer =$('.tracer')
        //     $('#ch-opacity').on('click', function(e) {
        //         $tracer.css('opacity', 0.5)
        //     })
            
        //     var canvas = $('#canvas').get(0);
        //     var ctx = canvas.getContext('2d');
        //     ctx.clearRect(0, 0, 550, 550);
        //     ctx.fillText('这里是 canvas', 200, 200);
        // })
    </script>
</body>
</html>